package com.jckl.foodathon.dao;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;

public class FoodathonDAOGenerator {

	public static void main(String[] args) throws Exception {
		Schema schema = new Schema(1, "com.jckl.foodathon.sqlite.model");
		schema.setDefaultJavaPackageDao("com.jckl.foodathon.sqlite.dao");
		schema.setDefaultJavaPackageTest("com.jckl.foodathon.sqlite.test");

		createDB(schema);
		new DaoGenerator().generateAll(schema, "../Foodathon/src");
	}

	private static void createDB(Schema schema) {
		
		// Table Update
		Entity tables = schema.addEntity("TB_Tables");
		tables.addIdProperty();
		tables.addStringProperty("Name");
		tables.addDateProperty("UpdatedDate");

		// Brand Table
		Entity brand = schema.addEntity("TB_Brand");
		brand.addIdProperty();
		brand.addStringProperty("name").notNull();

		// Store Table
		Entity store = schema.addEntity("TB_Store");
		store.addIdProperty();
		store.addStringProperty("name").notNull();
		store.addStringProperty("address_unitNumber");
		store.addStringProperty("address_buildingName");
		store.addStringProperty("address_streetName");
		store.addStringProperty("address_area");
		store.addStringProperty("address_postcode");
		store.addStringProperty("address_state");
		store.addStringProperty("address_country");
		store.addDoubleProperty("longitude");
		store.addDoubleProperty("latitude");
		store.addStringProperty("contactNo");
		store.addStringProperty("contactPerson");
		store.addStringProperty("notes");
		store.addByteArrayProperty("images");
		store.addStringProperty("website");
		store.addStringProperty("email");
		
		// Blogger Table
		Entity blogger = schema.addEntity("TB_Blogger");
		blogger.addIdProperty();
		blogger.addStringProperty("name").notNull();
		blogger.addStringProperty("blogURL");
		blogger.addStringProperty("aurthor");
		blogger.addByteArrayProperty("image");
		
		// Blog Table
		Entity blog = schema.addEntity("TB_Blog");
		blog.addIdProperty();
		blog.addStringProperty("title");
		blog.addStringProperty("blogURL");
		blog.addDateProperty("postDate");
		
		// Store <> Brand
		Property brandId = store.addLongProperty("brandId").getProperty();
		store.addToOne(brand, brandId);
		ToMany brandToStores = brand.addToMany(store, brandId);
		brandToStores.setName("stores");
		
		// Blogger <> Blog
		Property bloggerId = blog.addLongProperty("bloggerId").getProperty();
		blog.addToOne(blogger, bloggerId);
		ToMany bloggerToBlogs = blogger.addToMany(blog, bloggerId);
		bloggerToBlogs.setName("blogs");
		
		// Store <> Blog
		Property storeId = blog.addLongProperty("storeId").getProperty();
		blog.addToOne(store, storeId);
		ToMany storeToBlog = store.addToMany(blog, storeId);
		storeToBlog.setName("blogs");
		
	}

}
